package Strings_Collections;

        import java.util.Map;
        import java.util.HashMap;
        import java.util.StringTokenizer;
public class 词频统计和排序输出 {
    //获取单词的数量
    public Map<String, Integer> getWordCount(String str) {
        Map<String, Integer> map = new HashMap<String, Integer>();

        //请在此添加实现代码
        /********** Begin **********/
        StringTokenizer tkizer = new StringTokenizer(str);
        String word;
        int count = 0;

        while(tkizer.hasMoreTokens()){
            word = tkizer.nextToken(" .,:?!\"\"‘’;\n");
            if(map.containsKey(word)){
                count = map.get(word); // 获取该word的值
                map.put(word, count + 1);
            }else{
                map.put(word, 1);
            }
        }
        /********** End **********/

        return map;
    }
}
